//% color="#FF6B35" iconWidth=50 iconHeight=40
namespace HuskylensV2 {
    
    // === 通用设置 ===
    //% block="General Settings" blockType="tag"
    export function generalSettings() {}

    //% block="Initialize HUSKYLENS 2 via I2C until success " blockType="command"
    export function initialize(parameter: any, block: any) {
      
        Generator.addImport('from pinpong.board import Board\nfrom dfrobot_huskylensv2 import *');
        Generator.addInit("defaultBoardSensorImport", "Board().begin()", 2);
        Generator.addInit("huskylens", "huskylens = HuskylensV2_I2C()\nhuskylens.knock()", 2);
    
 
    }

    //% block="Initialize HUSKYLENS 2 via UART[UART] BAUD[BAUD] until success" blockType="command"
    //% UART.shadow="string" UART.defl="/dev/ttySP0"
    //% BAUD.shadow="dropdown" BAUD.options="BAUD"
    export function initialize1(parameter: any, block: any) {
        let uart = parameter.UART.code;
        let baud = parameter.BAUD.code;
        Generator.addImport('from pinpong.board import Board\nfrom dfrobot_huskylensv2 import *');
        Generator.addInit("defaultBoardSensorImport", "Board().begin()", 2);
        Generator.addInit("huskylens", `huskylens = HuskylensV2_UART(tty_name=${uart}, baudrate=${baud})\nhuskylens.knock()`, 2);
    }

    // === 算法切换 ===
    //% block="Switch Algorithm" blockType="tag"
    export function switchAlgorithmmethod() {}
    //% block="Switch Algorithm [ALGORITHM]" blockType="command"
    //% ALGORITHM.shadow="dropdown" ALGORITHM.options="ALGORITHM"
    export function switchAlgorithm(parameter: any, block: any) {
        let algorithm = parameter.ALGORITHM.code;
        Generator.addCode(`huskylens.switchAlgorithm(${algorithm})`);
    }

    // === 人脸识别 ===
    //% block="Face Recognition" blockType="tag"
    export function faceRecognition() {}

    //% block="Request face recognition data and save into the result" blockType="command"
    export function requestFaceData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_FACE_RECOGNITION)`);
    }

    //% block="Face detected?" blockType="boolean"
    export function faceDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_FACE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of face closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="FACE_PROPERTY"
    export function nearestFace(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
         Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_FACE_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_FACE_RECOGNITION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Total detected faces amount" blockType="reporter"
    export function totalFaces(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_FACE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of Face No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="FACE_PROPERTY"
    export function faceProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode(`huskylens.getCachedResultByIndex(ALGORITHM_FACE_RECOGNITION, ${index}-1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_FACE_RECOGNITION, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }
   //% block="Total amount of learned face IDs" blockType="reporter"
    export function totalLearnedFaces(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_FACE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Face ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function faceIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_FACE_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }
   //% block="Total amount of Face with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalFaceWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_FACE_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }
    
    //% block="[PROPERTY] of face with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="FACE_PROPERTY_ID"
    export function faceWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_FACE_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_FACE_RECOGNITION, ${id}) else -1`, Generator.ORDER_UNARY_POSTFIX]);


    }
    //% block="[PROPERTY] of face No.[INDEX] with ID [ID] " blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="FACE_PROPERTY_ID"
    export function FaceWithIDAndIndex(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_FACE_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_FACE_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);

    }

    // === 目标检测 ===
    //% block="Object Recognition" blockType="tag"
    export function objectDetection() {}

    //% block="Request object detection data and save into the result" blockType="command"
    export function requestObjectData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_OBJECT_RECOGNITION)`);
    }

    //% block="Object detected?" blockType="boolean"
    export function objectDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_OBJECT_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of object closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="OBJECT_PROPERTY"
    export function nearestObject(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_OBJECT_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_RECOGNITION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }
    

    //% block="Total detected object amount" blockType="reporter"
    export function totalObjects(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_OBJECT_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of object No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="OBJECT_PROPERTY"
    export function objectProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_OBJECT_RECOGNITION, ${index} - 1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_OBJECT_RECOGNITION, ${index} - 1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Total amount of learned object IDs" blockType="reporter"
    export function totalLearnedObjects(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_OBJECT_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Object ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function objectIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_OBJECT_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of object with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalObjectsWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
    
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_OBJECT_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);

    }

    //% block="[PROPERTY] of object with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="OBJECT_PROPERTY_ID"
    export function objectWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_OBJECT_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_OBJECT_RECOGNITION, ${id}) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of object No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="OBJECT_PROPERTY_ID"
    export function objectWithIDAndIndex(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_OBJECT_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_OBJECT_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }
  
    // === 物体追踪 ===
    //% block="Object Tracking" blockType="tag"
    export function objectTracking() {}
    //% block="Request onject tracking data and save into the result" blockType="command"
    export function requestObjectTrackingData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_OBJECT_TRACKING)`);
    }
    //% block="Object tracked?" blockType="boolean"
    export function objectTracked(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_OBJECT_TRACKING)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="[PROPERTY] of tracked object" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="TRACKING_PROPERTY"
    export function trackedObject(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING).${property} if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }


    // === 颜色识别 ===
    //% block="Color Recognition" blockType="tag"
    export function colorRecognition() {}

    //% block="Request color recognition data and save into the result" blockType="command"
    export function requestColorData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_COLOR_RECOGNITION)`);
    }

    //% block="Color patch detected?" blockType="boolean"
    export function colorBlobDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_COLOR_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of color patch closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="COLOR_PROPERTY"
    export function nearestColorBlob(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_COLOR_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_COLOR_RECOGNITION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Total amount of detected color patches" blockType="reporter"
    export function totalColorBlobs(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_COLOR_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of color patches No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="COLOR_PROPERTY"
    export function colorBlobProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_COLOR_RECOGNITION, ${index}-1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_COLOR_RECOGNITION, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Total amount of learned color IDs" blockType="reporter"
    export function totalLearnedColors(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_COLOR_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Color ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function colorIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_COLOR_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of color patches with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalColorBlobsWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_COLOR_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of color patch with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="COLOR_PROPERTY_ID"
    export function colorBlobWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_COLOR_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_COLOR_RECOGNITION, ${id}) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of color patches No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="COLOR_PROPERTY_ID"
    export function colorBlobWithIDProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_COLOR_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_COLOR_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }


    // === 物体分类 ===
    //% block="Object Classification" blockType="tag"
    export function objectClass() {}

    //% block="Request Object Class data and save into the result" blockType="command"
    export function requestObjectClassData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_OBJECT_CLASSIFICATION)`);
    }

    //% block=" Object Class detected?" blockType="boolean"
    export function ObjectClassDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_OBJECT_CLASSIFICATION)`, Generator.ORDER_UNARY_POSTFIX]);
    }


    //% block="[PROPERTY] of object closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="OBJECTCLASS_PROPERTY"
    export function nearestObjectClass(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        if (property === 'classID') {
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_OBJECT_CLASSIFICATION).classID + 1 if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_CLASSIFICATION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
           
        }else{
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_OBJECT_CLASSIFICATION).name if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_CLASSIFICATION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
        }
    }


    // === 自学习分类 ===
    //% block="Self-Learning Classifier" blockType="tag"
    export function objectClassification() {}

    //% block="Request Self-Learning Classifier data and save into the result" blockType="command"
    export function requestClassificationData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_SELF_LEARNING_CLASSIFICATION)`);
    }

    //% block="Self-learning classification of objects detected?" blockType="boolean"
    export function objectClassified(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_SELF_LEARNING_CLASSIFICATION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of Self-learning classification of objects closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="CLASSIFICATION_PROPERTY"
    export function nearestClassifiedObject(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_SELF_LEARNING_CLASSIFICATION).${property} if huskylens.getCachedCenterResult(ALGORITHM_SELF_LEARNING_CLASSIFICATION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }




    // === 实例分割 ===
    //% block="Instance Segmentation" blockType="tag"
    export function instanceSegmentation() {}

    //% block="Request instance segmentation data and save into the result" blockType="command"
    export function requestInstanceSegmentationData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_SEGMENT)`);
    }

    //% block="Instance detected?" blockType="boolean"
    export function instanceDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_SEGMENT)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of instance closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="INSTANCE_PROPERTY"
    export function nearestInstance(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_SEGMENT).${property} if huskylens.getCachedCenterResult(ALGORITHM_SEGMENT) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Total amount of detected instances" blockType="reporter"
    export function totalInstances(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_SEGMENT)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of instance No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="INSTANCE_PROPERTY"
    export function instanceProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_SEGMENT, ${index} - 1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_SEGMENT, ${index} - 1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Total amount of learned instance IDs" blockType="reporter"
    export function totalLearnedInstances(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_SEGMENT)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Instance ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function instanceIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_SEGMENT, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of instances with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalInstancesWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_SEGMENT, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of instance with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="INSTANCE_PROPERTY_ID"
    export function instanceWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_SEGMENT, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_SEGMENT, ${id}) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of instance No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="INSTANCE_PROPERTY_ID"
    export function instanceWithIDAndIndex(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_SEGMENT, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_SEGMENT, ${id}, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }



    // === 手势识别 ===
    //% block="Hand Recognition" blockType="tag"
    export function handKeypoints() {}

    //% block="Request hand guesture recognition data and save into the result" blockType="command"
    export function requestPalmData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_HAND_RECOGNITION)`);
    }

    //% block="Gesture detected?" blockType="boolean"
    export function palmDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_HAND_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of the hand gesture closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="PALM_PROPERTY"
    export function nearestPalm(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;

            Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_HAND_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_HAND_RECOGNITION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
        
    }

    //% block="Total amount of detected hand gestures" blockType="reporter"
    export function totalPalms(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_HAND_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of hand gesture No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="PALM_PROPERTY"
    export function palmProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;

        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_HAND_RECOGNITION, ${index}-1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_HAND_RECOGNITION, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
        
    }
    //% block="Total amount of learned hand gesture IDs" blockType="reporter"
    export function totalLearnedGestures(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_HAND_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Gesture ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function gestureIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_HAND_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of detected gestures with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalGesturesWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_HAND_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY]  of hand gesture with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="PALM_PROPERTY_ID"
    export function palmWithIDProperty(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
 
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_HAND_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_HAND_RECOGNITION, ${id}) else -1`, Generator.ORDER_UNARY_POSTFIX]);
        
    }

    //% block="[PROPERTY] of hand gesture No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="PALM_PROPERTY_ID"
    export function gestureWithIDProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;

        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_HAND_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_HAND_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
        
    }





    // === 姿态识别 ===
    //% block="Pose Recognition" blockType="tag"
    export function humanPoseKeypoints() {}

    //% block="Request human pose data and save into the result" blockType="command"
    export function requestHumanPoseData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_POSE_RECOGNITION)`);
    }

    //% block="Human body detected?" blockType="boolean"
    export function humanBodyDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_POSE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of the human pose closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="HUMAN_PROPERTY"
    export function nearestHumanBody(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;

        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1`, Generator.ORDER_ATOMIC]);
        
    }

    //% block="Total amount of detected human poses" blockType="reporter"
    export function totalHumanBodies(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_POSE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of human pose No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="HUMAN_PROPERTY"
    export function humanBodyProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;

        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_POSE_RECOGNITION, ${index}-1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_POSE_RECOGNITION, ${index}-1) else -1`, Generator.ORDER_ATOMIC]);
        
    }
    //% block="Total amount of learned human pose IDs" blockType="reporter"
    export function totalLearnedHumanBodies(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_POSE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Pose ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function poseIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_POSE_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of poses with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalPosesWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_POSE_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY]  of pose with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="HUMAN_PROPERTY_ID"
    export function poseWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;

        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_POSE_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_POSE_RECOGNITION, ${id}) else -1`, Generator.ORDER_ATOMIC]);
        
    }

    //% block="[PROPERTY] of pose No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="HUMAN_PROPERTY_ID"
    export function poseWithIDProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;

        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_POSE_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_POSE_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_ATOMIC]);
   
    }



    // === 车牌识别 ===
    //% block="License Plate Recognition" blockType="tag"
    export function licensePlateRecognition() {}

    //% block="Request license plate recognition data and save into the result" blockType="command"
    export function requestLicensePlateData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_LICENSE_RECOGNITION)`);
    }

    //% block="License plate detected?" blockType="boolean"
    export function licensePlateDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_LICENSE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of the license plate closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="LICENSE_PROPERTY"
    export function nearestLicensePlate(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_LICENSE_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_LICENSE_RECOGNITION) else -1`, Generator.ORDER_ATOMIC]);
    }

    //% block="Total amount of detected license plates" blockType="reporter"
    export function totalLicensePlates(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_LICENSE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of license plate No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="LICENSE_PROPERTY"
    export function licensePlateProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_LICENSE_RECOGNITION, ${index}-1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_LICENSE_RECOGNITION, ${index}-1) else -1`, Generator.ORDER_ATOMIC]);
    }
    //% block="Total amount of learned pose IDs" blockType="reporter"
    export function totalLearnedLicensePlates(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_LICENSE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="License plate ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function licensePlateIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_LICENSE_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of license plate with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalLicensePlatesWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_LICENSE_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of license plate with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="LICENSE_PROPERTY_ID"
    export function licensePlateWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_LICENSE_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_LICENSE_RECOGNITION, ${id}) else -1`, Generator.ORDER_ATOMIC]);
    }

    //% block="[PROPERTY] of license plate No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="LICENSE_PROPERTY_ID"
    export function licensePlateWithIDProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_LICENSE_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_LICENSE_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_ATOMIC]);
    }



    // === 文字识别 ===
    //% block="Optical Char Recognition" blockType="tag"
    export function textRecognition() {}

    //% block="Request text recognition data and save into the result" blockType="command"
    export function requestTextData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_OCR_RECOGNITION)`);
    }

    //% block="Text detected?" blockType="boolean"
    export function textDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_OCR_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of the text area closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="TEXT_PROPERTY"
    export function nearestTextArea(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION) else -1`, Generator.ORDER_ATOMIC]);
    }

    //% block="Total amount of detected text areas" blockType="reporter"
    export function totalTextAreas(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_OCR_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of text area No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="TEXT_PROPERTY"
    export function textAreaProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_OCR_RECOGNITION, ${index}-1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_OCR_RECOGNITION, ${index}-1) else -1`, Generator.ORDER_ATOMIC]);
    }
    //% block="Total amount of learned text IDs" blockType="reporter"
    export function totalLearnedTextAreas(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_OCR_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Text area ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function textAreaIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_OCR_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of text areas with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalTextAreasWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_OCR_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of text area with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="TEXT_PROPERTY_ID"
    export function textAreaWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_OCR_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_OCR_RECOGNITION, ${id}) else -1`, Generator.ORDER_ATOMIC]);
    }

    //% block="[PROPERTY] of text area No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="TEXT_PROPERTY_ID"
    export function textAreaWithIDProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_OCR_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_OCR_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_ATOMIC]);
    }


    // === 巡线 ===
    //% block="Line Tracking" blockType="tag"
    export function lineTracking() {}
    //% block="Request line tracking data and save into the result" blockType="command"
    export function requestLineTrackingData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_LINE_TRACKING)`);
    }
    //% block="Line detected?" blockType="boolean"
    export function lineDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_LINE_TRACKING)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="[PROPERTY] of current branch line" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="LINE_PROPERTY"
    export function currentBranchLine(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCurrentBranch(ALGORITHM_LINE_TRACKING,'${property}')`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Total amount of branches" blockType="reporter"
    export function branchCount(parameter: any, block: any) {
        Generator.addCode([`huskylens.getUpcomingBranchCount(ALGORITHM_LINE_TRACKING)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="[PROPERTY] component of branch No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="LINE_PROPERTY"
    export function lineProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getBranch(ALGORITHM_LINE_TRACKING, ${index}-1,'${property}')`, Generator.ORDER_UNARY_POSTFIX]);
    }
   
    
    // === 表情识别 ===
    //% block="Emotion Recognition" blockType="tag"
    export function expressionRecognition() {}

    //% block="Request facial expression recognition data and save into the result" blockType="command"
    export function requestExpressionData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_EMOTION_RECOGNITION)`);
    }

    //% block="Expression detected?" blockType="boolean"
    export function expressionDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_EMOTION_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of the facial expression closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="EXPRESSION_PROPERTY"
    export function nearestExpression(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_EMOTION_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_EMOTION_RECOGNITION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Total amount of detected facial expressions" blockType="reporter"
    export function totalExpressions(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_EMOTION_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of facial expression No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="EXPRESSION_PROPERTY"
    export function expressionProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_EMOTION_RECOGNITION, ${index}-1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_EMOTION_RECOGNITION, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Total amount of learned facial expression IDs" blockType="reporter"
    export function totalLearnedExpressions(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_EMOTION_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Facial expression ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function expressionIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_EMOTION_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of facial expressions with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalExpressionsWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_EMOTION_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of facial expression with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="EXPRESSION_PROPERTY_ID"
    export function expressionWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_EMOTION_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_EMOTION_RECOGNITION, ${id}) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of facial expression No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="EXPRESSION_PROPERTY_ID"
    export function expressionWithIDProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_EMOTION_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_EMOTION_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }


    // === 标签识别 ===
    //% block="Tag Recognition" blockType="tag"
    export function tagRecognition() {}

    //% block="Request tag recognition data and save into the result" blockType="command"
    export function requestTagData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_TAG_RECOGNITION)`);
    }

    //% block="Tag detected?" blockType="boolean"
    export function tagDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_TAG_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of the tag closest to center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="TAG_PROPERTY"
    export function nearestTag(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_TAG_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_TAG_RECOGNITION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Total amount of detected tags" blockType="reporter"
    export function totalTags(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_TAG_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of tag No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="TAG_PROPERTY"
    export function tagProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_TAG_RECOGNITION, ${index}-1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_TAG_RECOGNITION, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Total amount of learned tag IDs" blockType="reporter"
    export function totalLearnedTags(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_TAG_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Tag ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function tagIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_TAG_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of tags with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalTagsWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_TAG_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of tag with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="TAG_PROPERTY_ID"
    export function tagWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_TAG_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_TAG_RECOGNITION, ${id}) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of tag No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="TAG_PROPERTY_ID"
    export function tagWithIDProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_TAG_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_TAG_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }


    
    // === 二维码识别 ===
    //% block="QR Code Recognition" blockType="tag"
    export function qrCodeRecognition() {}

    //% block="Request QR code recognition data and save into result" blockType="command"
    export function requestQRCodeData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_QRCODE_RECOGNITION)`);
    }

    //% block="QR code detected?" blockType="boolean"
    export function qrCodeDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_QRCODE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of the QR code closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="QR_PROPERTY"
    export function nearestQRCode(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_QRCODE_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_QRCODE_RECOGNITION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Total amount of detected QR codes" blockType="reporter"
    export function totalQRCodes(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_QRCODE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of QR code No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="QR_PROPERTY"
    export function qrCodeProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_QRCODE_RECOGNITION, ${index}-1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_QRCODE_RECOGNITION, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Total amount of learned QR code IDs" blockType="reporter"
    export function totalLearnedQRCodes(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_QRCODE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="QR code ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function qrCodeIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_QRCODE_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of QR codes with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalQRCodesWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_QRCODE_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of QR code with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="QR_PROPERTY_ID"
    export function qrWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_QRCODE_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_QRCODE_RECOGNITION, ${id}) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of QR code No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="QR_PROPERTY_ID"
    export function qrWithIDProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_QRCODE_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_QRCODE_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }



    // === 条形码识别 ===
    //% block="Barcode Recognition" blockType="tag"
    export function barcodeRecognition() {}

    //% block="Request barcode recognition data and save into the result" blockType="command"
    export function requestBarcodeData(parameter: any, block: any) {
        Generator.addCode(`huskylens.getResult(ALGORITHM_BARCODE_RECOGNITION)`);
    }

    //% block="Barcode detected?" blockType="boolean"
    export function barcodeDetected(parameter: any, block: any) {
        Generator.addCode([`huskylens.available(ALGORITHM_BARCODE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of the barcode closest to the center" blockType="reporter"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="BARCODE_PROPERTY"
    export function nearestBarcode(parameter: any, block: any) {
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(ALGORITHM_BARCODE_RECOGNITION).${property} if huskylens.getCachedCenterResult(ALGORITHM_BARCODE_RECOGNITION) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Total amount of detected barcodes" blockType="reporter"
    export function totalBarcodes(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultNum(ALGORITHM_BARCODE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of barcode No.[INDEX]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="BARCODE_PROPERTY"
    export function barcodeProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByIndex(ALGORITHM_BARCODE_RECOGNITION, ${index}-1).${property} if huskylens.getCachedResultByIndex(ALGORITHM_BARCODE_RECOGNITION, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Total amount of learned barcode IDs" blockType="reporter"
    export function totalLearnedBarcodes(parameter: any, block: any) {
        Generator.addCode([`huskylens.getCachedResultMaxID(ALGORITHM_BARCODE_RECOGNITION)`, Generator.ORDER_UNARY_POSTFIX]);
    }
    //% block="Barcode ID [ID] exists?" blockType="boolean"
    //% ID.shadow="normal" ID.defl="1"
    export function barcodeIDExists(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`(huskylens.getCachedResultByID(ALGORITHM_BARCODE_RECOGNITION, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Total amount of barcodes with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    export function totalBarcodesWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(ALGORITHM_BARCODE_RECOGNITION, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of barcode with ID [ID]" blockType="reporter"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="BARCODE_PROPERTY_ID"
    export function barcodeWithID(parameter: any, block: any) {
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(ALGORITHM_BARCODE_RECOGNITION, ${id}).${property} if huskylens.getCachedResultByID(ALGORITHM_BARCODE_RECOGNITION, ${id}) else -1`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="[PROPERTY] of barcode No.[INDEX] with ID [ID]" blockType="reporter"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="BARCODE_PROPERTY_ID"
    export function barcodeWithIDProperty(parameter: any, block: any) {
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(ALGORITHM_BARCODE_RECOGNITION, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(ALGORITHM_BARCODE_RECOGNITION, ${id}, ${index}-1) else -1`, Generator.ORDER_ATOMIC]);
    }




    // === 自训练模型 ===
    //% block="self-trained model" blockType="tag"
    export function selfTrainedModel() {}

    //% block="HUSKYLENS 2 switch algorithm ID [NUM] until success" blockType="command"
    //% NUM.shadow="number" NUM.defl="128"
    export function selfTrainedModelswitchAlgorithm(parameter: any, block: any) {
        let num = parameter.NUM.code;
        Generator.addCode(`huskylens.switchAlgorithm(${num});`);
    }
    //% block="Algo ID [NUM] request data and save into the result" blockType="command"
    //% NUM.shadow="number" NUM.defl="128"
    export function requestData(parameter: any, block: any) {
        let num = parameter.NUM.code;

        Generator.addCode(`huskylens.getResult(${num});`);
    }

    //% block="Algo ID [NUM] object detected?" blockType="boolean"
    //% NUM.shadow="number" NUM.defl="128"
    export function Detected(parameter: any, block: any) {
        let num = parameter.NUM.code;
        Generator.addCode([`huskylens.available(${num})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Algo ID [NUM]  [PROPERTY] of the object closest to the center" blockType="reporter"
    //% NUM.shadow="number" NUM.defl="128"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="NUM_PROPERTY"
    export function nearest(parameter: any, block: any) {
        let num = parameter.NUM.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedCenterResult(${num}).${property} if huskylens.getCachedCenterResult(${num}) else -1`, Generator.ORDER_UNARY_POSTFIX]);
   
    }

    //% block="Algo ID [NUM] total amount of detected objects" blockType="reporter"
    //% NUM.shadow="number" NUM.defl="128"
    export function total(parameter: any, block: any) {
        let num = parameter.NUM.code;
        Generator.addCode([`huskylens.getCachedResultNum(${num})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Algo ID [NUM] [PROPERTY] of object No.[INDEX]" blockType="reporter"
    //% NUM.shadow="number" NUM.defl="128"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="NUM_PROPERTY"
    export function Property(parameter: any, block: any) {
        let num = parameter.NUM.code;
        let index = parameter.INDEX.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByIndex(${num}, ${index}-1).${property} if huskylens.getCachedResultByIndex(${num}, ${index}-1) else -1`, Generator.ORDER_UNARY_POSTFIX]);

    }
    //% block="Algo ID [NUM] total amount of learned object IDs" blockType="reporter"
    //% NUM.shadow="number" NUM.defl="128"
    export function totalLearned(parameter: any, block: any) {
        let num = parameter.NUM.code;
        Generator.addCode([`huskylens.getCachedResultMaxID(${num})`, Generator.ORDER_UNARY_POSTFIX]);

    }
    //% block="Algo ID [NUM] object ID [ID] exists?" blockType="boolean"
    //% NUM.shadow="number" NUM.defl="128"
    //% ID.shadow="normal" ID.defl="1"
    export function IDExists(parameter: any, block: any) {
        let num = parameter.NUM.code;
        let id = parameter.ID.code;
        
        Generator.addCode([`(huskylens.getCachedResultByID(${num}, ${id}) is not None)`, Generator.ORDER_RELATIONAL]);
    }

    //% block="Algo ID [NUM] total amount of object with ID [ID]" blockType="reporter"
    //% NUM.shadow="number" NUM.defl="128"
    //% ID.shadow="normal" ID.defl="1"
    export function totalWithID(parameter: any, block: any) {
        let num = parameter.NUM.code;
        let id = parameter.ID.code;
        Generator.addCode([`huskylens.getCachedResultNumByID(${num}, ${id})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="Algo ID [NUM] [PROPERTY] of object with ID [ID]" blockType="reporter"
    //% NUM.shadow="number" NUM.defl="128"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="NUM_PROPERTY_ID"
    export function WithID(parameter: any, block: any) {
        let num = parameter.NUM.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedResultByID(${num}, ${id}).${property} if huskylens.getCachedResultByID(${num}, ${id}) else -1`, Generator.ORDER_UNARY_POSTFIX]);

    }

    //% block="Algo ID [NUM] [PROPERTY] of object No.[INDEX] with ID [ID]" blockType="reporter"
    //% NUM.shadow="number" NUM.defl="128"
    //% INDEX.shadow="normal" INDEX.defl="1"
    //% ID.shadow="normal" ID.defl="1"
    //% PROPERTY.shadow="dropdown" PROPERTY.options="NUM_PROPERTY_ID"
    export function WithIDProperty(parameter: any, block: any) {
        let num = parameter.NUM.code;
        let index = parameter.INDEX.code;
        let id = parameter.ID.code;
        let property = parameter.PROPERTY.code;
        Generator.addCode([`huskylens.getCachedIndexResultByID(${num}, ${id}, ${index}-1).${property} if huskylens.getCachedIndexResultByID(${num}, ${id}, ${index}-1) else -1`, Generator.ORDER_ATOMIC]);

    }


}
